<template>
  <div class="merchandise-management views-container">
    <share-link :config="shareLinkConfig" ref="sharelink">
      <template slot="title">-商品</template>
      <template slot="el-form-item">
        <el-form-item label="商品小程序路径" v-if="shareLinkConfig.params.qrUrl">
          <el-input style="width: 270px;" readonly placeholder="请输入内容" v-model="shareLinkConfig.params.qrUrl" class="input-with-select">
            <el-button slot="append" @click="handleClipboard(shareLinkConfig.params.qrUrl,$event)">复制</el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="商品公众号链接" v-if="shareLinkConfig.params.linkUrl">
          <el-input style="width: 270px;" readonly placeholder="请输入内容" v-model="shareLinkConfig.params.linkUrl" class="input-with-select">
            <el-button slot="append" @click="handleClipboard(shareLinkConfig.params.linkUrl,$event)">复制</el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="直播商品链接" v-if="shareLinkConfig.params.url">
          <el-input style="width: 270px;" readonly placeholder="请输入内容" v-model="shareLinkConfig.params.url" class="input-with-select">
            <el-button slot="append" @click="handleClipboard(shareLinkConfig.params.url,$event)">复制</el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="短链接" v-if="shareLinkConfig.params.weChat_short_url">
          <el-input style="width: 270px;" readonly placeholder="请输入内容" v-model="shareLinkConfig.params.weChat_short_url" class="input-with-select">
            <el-button slot="append" @click="handleClipboard(shareLinkConfig.params.weChat_short_url,$event)">复制</el-button>
          </el-input>
        </el-form-item>
      </template>
    </share-link>

    <!-- 活动选择弹窗 -->
    <el-dialog title="活动管理" :visible.sync="activityDialog" :close-on-press-escape="false" :close-on-click-modal="false" width="25%" style="margin-top:10vh;">
      <el-form :model="activityForm">
        <el-form-item label="">
          <!-- <el-radio-group v-model="activityForm.active">
            <el-radio style="display:block;margin:30px 0;" v-for="(item,index) in activityList" :key="index" :label="'加入'+item.name" :name="item.name"></el-radio>
          </el-radio-group> -->
          <el-checkbox-group v-model="activityForm.active">
            <el-checkbox
              style="display:block;margin-bottom:30px;"
              v-for="(item,index) in activityList"
              :key="index"
              :label="item.id"
              :checked="item.checked"
              :value="item.id"
              :disabled="item.disabled"
              name="type">{{ item.name }}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="closeActivityDialog">取 消</el-button>
        <el-button type="primary" @click="submitActivityDialog">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="dialogVisibleImg" @close="clearRebate" width="50%" custom-class="reset-pwd wlm-form-dialog dialog-table">
      <div class="wlm-form" v-if="dialogVisibleImg">
        <div class="wlm-form-header wlm-dialog-fixheader">
          <span class="wlm-dialog-inlenr">批量设置{{openimgDialogType=='1'?'赠送积分':'积分抵扣'}}</span>
        </div>
        <el-scrollbar wrap-class="scrollbar-wrapper">
          <div class="wlm-form-content">
            <div class="wlm-dialog-main">
              <div class="wlm-dialog-content">
                <el-form ref="userForm" :model="formFormatData.formData" size="small" label-width="120px" class="retail-form" label-position="right">
                  <el-form-item label="购买商品赠送" prop="name" v-if="openimgDialogType=='1'">
                    <el-input v-model="rebate.give_integral" style="width:200px;">
                      <template slot="append">积分</template></el-input>
                  </el-form-item>
                  <el-form-item label="积分抵扣" prop="name" v-if="openimgDialogType=='2'">
                    <el-radio-group v-model="rebate.rebate">
                      <el-radio :label="1">开</el-radio>
                      <el-radio :label="2">关</el-radio>
                    </el-radio-group>
                  </el-form-item>
                  <el-form-item label="最高抵扣" prop="name" v-if="openimgDialogType=='2'">
                    <el-input v-model="rebate.max_rebate_money" style="width:200px;">
                      <template slot="append">元</template>
                    </el-input>
                  </el-form-item>
                </el-form>
              </div>
            </div>
          </div>
        </el-scrollbar>
      </div>
      <footer class="flex-row flex-align-c flex-justify-c wlm-dialog-fixfooter">
        <el-button size="small" type="primary" @click="saveimgDialog">确定</el-button>
      </footer>
    </el-dialog>
    <el-dialog :visible.sync="dialogTableVisible" custom-class="reset-pwd wlm-form-dialog dialog-table">
      <div class="wlm-form" v-if="dialogTableVisible && ($type && $type !== 'goods_up')">
        <div class="wlm-form-header wlm-dialog-fixheader">
          <span class="wlm-dialog-inlenr">编辑多规格</span>
        </div>
        <el-table ref="specTabel" :data="tableFormatData.announcement.tableData[$index]['sku']" style="width: 100%">
          <el-table-column label="规格名称">
            <template slot-scope="scope">
              <span>{{scope.row.title}}</span>
            </template>
          </el-table-column>
          <el-table-column label="售卖价" v-if="$type === 'price'">
            <template slot-scope="scope">
              <el-input size="medium" v-model="scope.row.goods_price" @blur="changeTableItem({goods_id:scope.row.goods_id,goods_price:scope.row.goods_price,line_price:scope.row.line_price,spec_sku_id:scope.row.spec_sku_id},tableFormatData.announcement.change.goods_price)"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="市场价" v-if="$type === 'price'">
            <template slot-scope="scope">
              <el-input size="medium" v-model="scope.row.line_price" @blur="changeTableItem({goods_id:scope.row.goods_id,goods_price:scope.row.goods_price,line_price:scope.row.line_price,spec_sku_id:scope.row.spec_sku_id},tableFormatData.announcement.change.goods_price)"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="库存" v-if="$type === 'num'">
            <template slot-scope="scope">
              <el-input size="medium" v-model="scope.row.stock_num" @blur="changeTableItem({goods_id:scope.row.goods_id,stock_num:scope.row.stock_num,spec_sku_id:scope.row.spec_sku_id},tableFormatData.announcement.change.stock_num)"></el-input>
            </template>
          </el-table-column>
        </el-table>
        <footer class="flex-row flex-align-c flex-justify-c wlm-dialog-fixfooter">
          <el-button size="small" @click="dialogTableVisible = false" type="primary">关闭</el-button>
        </footer>
      </div>
      <div class="wlm-form" v-if="dialogTableVisible && ($type && $type === 'goods_up')">
        <div class="wlm-form-header wlm-dialog-fixheader">
          <span class="wlm-dialog-inlenr">批量上架</span>
        </div>
        <el-form style="margin-top: 20px;" :ref="formFormatData.key" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="120px" class="retail-form" label-position="right">
          <el-form-item label="上架时间">
            <el-radio-group v-model="formFormatData.formData.goods_status">
              <el-radio :label="10">立即上架</el-radio>
              <el-radio :label="30">设置上架时间</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="" v-if="formFormatData.formData.goods_status === 30">
            <el-date-picker :picker-options="disabledDateOptions" v-model="formFormatData.formData.uppertime" value-format="timestamp" type="datetime" placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
        </el-form>
        <footer class="flex-row flex-align-c flex-justify-c wlm-dialog-fixfooter">
          <el-button size="small" @click="saveDialog" type="primary">保存</el-button>
          <el-button size="small" @click="dialogTableVisible = false" type="primary">关闭</el-button>
        </footer>
      </div>
    </el-dialog>
    <div class="wlm-table">
      <div class="wlm-table-hearder-btn">
          <router-link target="_blank" :to="{path:'/merchandise/merchandiseManagementAdd',query:{  store_user_id:$route.query.store_user_id?$route.query.store_user_id:'',
                  h_aid:$route.query.h_aid?$route.query.h_aid:'',}}">
          <el-button size="small" type="primary">添加商品</el-button>
        </router-link>
      </div>
      <div class="wlm-table-header">
        <el-form :model="tableFormatData.announcement.files" size="small" label-width="90px" class="retail-form" label-position="right">
          <el-form-item label="" class="filter">
            <el-form-item label="商品名称：" class="search">
              <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.announcement.files.name" placeholder="请输入商品名称" style="width:200px;"></el-input>
            </el-form-item>
            <!-- <el-form-item label="商品分类：" class="filter">
              <el-select v-model="tableFormatData.announcement.files.category_id" placeholder="请选择">
                            <el-option v-for="item in categoryData" :key="item.value" :label="item.name" :value="item.category_id">
                            </el-option>
                        </el-select>
              <el-cascader :props="myProps" :options="categoryData" :show-all-levels="false" v-model="category_array" @change="categoryChange">
              </el-cascader>
            </el-form-item> -->
            <el-form-item label="商品类型：" class="filter">

              <el-select v-model="tableFormatData.announcement.files.transport_type" placeholder="">
                <el-option label="全部" value=""> </el-option>
                <el-option label="核销商品" :value="10"> </el-option>
                <el-option label="实物商品" :value="20"> </el-option>
                <el-option label="卡密商品" :value="30"> </el-option>
                <el-option label="团购商品" :value="40" v-if="patSetting.plugin.cgp.open">
                </el-option>
                <el-option label="礼包商品" :value="50"></el-option>
                <el-option label="票务商品" :value="60"></el-option>
                <!-- <el-option label="阶梯价商品" :value="is_step_price"></el-option> -->

              </el-select>
            </el-form-item>
            <el-form-item label="商品排序：" class="filter">
              <el-select v-model="tableFormatData.announcement.files.order" placeholder="请选择">
                <el-option label="销量排序" value="sales">
                </el-option>
                <el-option label="排序大小排序" value="sort">
                </el-option>
                <el-option label="下架时间排序" value="under">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="商家搜索：" class="filter">
              <el-select filterable v-model="tableFormatData.announcement.files.business_id" placeholder="请选择或输入关键词搜索">
                <el-option v-for="item in shopData" :disabled="item.storenum==0" :key="item.value" :label="item.name" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-form-item>
          <el-form-item label="" class="filter-btns">
            <el-button type="primary" @click="filesSerch">筛选</el-button>
            <el-button type="text" @click="filesEmptyBefore">清空筛选条件</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="wlm-table-content">
        <el-tabs v-model="tableFormatData.announcement.files.goodsType" type="card" @tab-click="filesSerch">
          <!-- @tab-click="filesSerch" -->
          <el-tab-pane :label="`售卖中(${goodsType.sale})`" name="sale"></el-tab-pane>
          <el-tab-pane :label="`已售罄(${goodsType.hasSale})`" name="hasSale"></el-tab-pane>
          <el-tab-pane :label="`仓库中(${goodsType.depot})`" name="depot"></el-tab-pane>
        </el-tabs>
        <el-table :ref="tableFormatData.announcement.key" :data="tableFormatData.announcement.tableData" @selection-change="handleSelectionChange" style="width: 100%">
          <el-table-column type="selection" width="55">
          </el-table-column>
          <el-table-column prop="sort" width="80" label="排序" sortable>
            <template slot-scope="scope">
              <el-input-number
@blur="changeTableItem({ids:[scope.row.goods_id],goods_sort:scope.row.goods_sort},tableFormatData.announcement.change.sort)"
              style="width:100%;"
size="mini"
v-model="scope.row.goods_sort"
:controls="false"></el-input-number>
            </template>
          </el-table-column>
          <el-table-column prop="date" label="商品LOGO" min-width="35">
            <template slot-scope="scope" v-if="Array.isArray(scope.row.image) &&scope.row.image.length>0">
              <div class="wlm-table-logos">
                <img class="logo" :src="scope.row.image[0]['file_path']">
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="date" label="商品名称" min-width="100">
            <template slot-scope="scope" class="popover">
              <el-popover trigger="hover" placement="top-start">
                <!-- <div class="flex-col"> -->
                <div class="flex-row flex-align-c" style="margin-bottom:10px;width:400px;">
                  <span style="white-space: nowrap; margin-right:8px;">商品名称: </span>
                  <el-input size="mini" type="textarea" v-model="scope.row.goods_name" :maxlength="300" style="margin-right:10px"></el-input>
                  <el-button type="text" size="mini" @click="changeTableItem({goods_id:scope.row.goods_id,goods_name:scope.row.goods_name},tableFormatData.announcement.change.goods_name)">确定</el-button>
                  <!-- <div style="margin:0 6px;" class="orders-blue">|</div>
                                    <el-button type="text" size="mini">取消</el-button> -->
                </div>
                <!-- </div> -->
                <div slot="reference" class="name-wrapper">
                  <div class="pointer ellips_line2" style="max-width:200px;max-height: 51px;overflow: hidden;">
                    <span @mousemove="mouseenter(scope, true, 'showEditNameBtn')" @mouseout="mouseenter(scope, false, 'showEditNameBtn')">{{ scope.row.goods_name }}</span>
                    <svg-icon v-if="scope.row.showEditNameBtn" icon-class="editIcon" />
                  </div>
                </div>
              </el-popover>
              <el-tag style="width: 36px;font-size:12px;" size="mini" v-if="scope.row.sale_type!=0">{{scope.row.sale_type==1?'秒杀':scope.row.sale_type==2?'拼团':scope.row.sale_type==3?'抽奖':scope.row.sale_type==4?'砍价':scope.row.sale_type==5?'免单':''}}</el-tag>
              <el-tag style="width: 60px;font-size:12px;" size="mini" v-if="scope.row.member_exclusive==1">会员专属</el-tag>
              <el-tag style="width: 46px;font-size:12px;" size="mini" v-if="scope.row.is_member_price==1">会员价</el-tag>
              <el-tag style="width: 36px;font-size:12px;" size="mini" v-if="scope.row.transport_type==30">卡密</el-tag>
              <el-tag style="width: 36px;font-size:12px;" size="mini" v-if="scope.row.transport_type==60">票务</el-tag>
              <el-tag style="width: 36px;font-size:12px;" size="mini" v-if="scope.row.transport_type==50">礼包</el-tag>
              <!-- <el-tag style="width: 36px;font-size:12px;" size="mini" v-if="scope.row.transport_type==10 && ">预约</el-tag> -->
            </template>
          </el-table-column>
          <!-- <el-table-column prop="date" label="商品分类" min-width="70">
            <template slot-scope="scope" v-if="scope.row.category_data">
              <p v-for="(item, index) in scope.row.category_data" :key="index" v-if="item.name&&scope.row.category_data">{{`${item.name}: ${item.child?item.child.length>1?item.child.join('/'):item.child[0]:''}`}}</p>
              <p v-if="scope.row.category_data.length==0">-</p>
            </template>
          </el-table-column> -->
          <!-- <el-table-column prop="supplier_name" label="供应商">

          </el-table-column> -->
          <el-table-column prop="date" label="价格" min-width="35">
            <template slot-scope="scope" v-if="scope.row.sku&&scope.row.sku[0]">
              <el-popover trigger="click" placement="top" v-if="scope.row.spec_type==10">
                <div class="flex-row flex-align-c" style="margin-bottom:4px;">
                  <span style="white-space: nowrap; margin-right:8px;">售卖价: </span>
                  <el-input-number v-model="scope.row.sku[0]['goods_price']" @blur="changeTableItem({goods_id:scope.row.goods_id,goods_price:scope.row.sku[0]['goods_price'],line_price:scope.row.sku[0]['line_price']},tableFormatData.announcement.change.goods_price)" :controls="false" size="mini">
                  </el-input-number>
                </div>
                <div class="flex-row flex-align-c">
                  <span style="white-space: nowrap; margin-right:8px;">市场价: </span>
                  <el-input-number v-model="scope.row.sku[0]['line_price']" @blur="changeTableItem({goods_id:scope.row.goods_id,goods_price:scope.row.sku[0]['goods_price'],line_price:scope.row.sku[0]['line_price']},tableFormatData.announcement.change.goods_price)" :controls="false" size="mini">
                  </el-input-number>
                </div>
                <div slot="reference" class="name-wrapper">
                  <el-button type="text" v-if="scope.row.spec_type==10" class="pointer"><span @mousemove="mouseenter(scope, true, 'showEditPriceBtn')" @mouseout="mouseenter(scope, false, 'showEditPriceBtn')">{{ scope.row.sku[0]['goods_price'] }} </span>
                    <svg-icon v-if="scope.row.showEditPriceBtn" icon-class="editIcon" />
                  </el-button>
                </div>
              </el-popover>
              <el-button type="text" v-if="scope.row.spec_type==20" size="mini" class="pointer" @click="showDialog(scope,'price')"><span @mousemove="mouseenter(scope, true, 'showEditPriceBtn')" @mouseout="mouseenter(scope, false, 'showEditPriceBtn')">{{ scope.row.sku[0]['goods_price'] }}</span>
                <svg-icon v-if="scope.row.showEditPriceBtn" icon-class="editIcon" />
              </el-button>
            </template>
          </el-table-column>
          <!-- <el-table-column prop="supplier" label="团长佣金比例">
          </el-table-column> -->
          <el-table-column prop="date" label="库存/销量" min-width="55">
            <template slot-scope="scope" v-if="scope.row.sku&&scope.row.sku[0]">
              <el-popover trigger="click" placement="top" v-if="scope.row.spec_type==10&&scope.row.transport_type!=30" style="display: inline-block;">
                <div class="flex-row flex-align-c">
                  <span style="white-space: nowrap; margin-right:8px;">库存: </span>
                  <el-input size="mini" v-model="scope.row.sku[0]['stock_num']" @blur="changeTableItem({goods_id:scope.row.goods_id,stock_num:scope.row.sku[0]['stock_num'],spec_sku_id:scope.row.spec_sku_id},tableFormatData.announcement.change.stock_num)"></el-input>
                </div>
                <div slot="reference" class="name-wrapper">
                  <el-button type="text" v-if="scope.row.spec_type==10" class="pointer"><span @mousemove="mouseenter(scope, true, 'showEditStockBtn')" @mouseout="mouseenter(scope, false, 'showEditStockBtn')">{{`${scope.row.sku[0]['stock_num']}`}} </span>
                    <svg-icon v-if="scope.row.showEditStockBtn" icon-class="editIcon" />
                  </el-button>
                </div>
              </el-popover>
              <el-button type="text" style="display: inline-block;" v-if="scope.row.spec_type==20&&scope.row.transport_type!=30" size="mini" class="pointer" @click="showDialog(scope,'num')">
                <span @mousemove="mouseenter(scope, true, 'showEditStockBtn')" @mouseout="mouseenter(scope, false, 'showEditStockBtn')">
                  {{`${scope.row.stock}`}}</span>
                <svg-icon v-if="scope.row.showEditStockBtn" icon-class="editIcon" />
              </el-button>
              <span v-if="scope.row.transport_type==30">{{scope.row.stock}}</span><span> / {{scope.row.goods_sales}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="date" label="数据统计" min-width="45">
            <template slot-scope="scope">
              <p>已下单：
                <router-link tag="span" :to="{path:linkOrderType(scope.row.transport_type,scope.row.isexpress,scope.row.iszt), query :{ order_status:'10',goods_id:scope.row.goods_id}}">
                  <span class="pointer">{{scope.row.calc.all}}</span>
                </router-link>
              </p>
              <p>已支付：
                <router-link tag="span" :to="{path:linkOrderType(scope.row.transport_type,scope.row.isexpress,scope.row.iszt), query :{ order_status:'20',goods_id:scope.row.goods_id}}">
                  <span class="pointer">{{scope.row.calc.pay}}</span>
                </router-link>
              </p>
            </template>
          </el-table-column>
          <el-table-column prop="date" label="数据统计" min-width="45">
            <template slot-scope="scope">
              <p>已退款：
                <router-link tag="span" :to="{path:linkOrderType(scope.row.transport_type,scope.row.isexpress,scope.row.iszt), query :{ order_status:'30',goods_id:scope.row.goods_id}}">
                  <span class="pointer">{{scope.row.calc.refund}}</span>
                </router-link>
              </p>
              <p>已完成：
                <router-link tag="span" :to="{path:linkOrderType(scope.row.transport_type,scope.row.isexpress,scope.row.iszt), query :{ order_status:'40',goods_id:scope.row.goods_id}}">
                  <span class="pointer">{{scope.row.calc.done}}</span>
                </router-link>
              </p>
            </template>
          </el-table-column>
          <el-table-column prop="date" label="下架时间" min-width="60">
            <template slot-scope="scope">
               <span class="pointer">{{scope.row.under_time ? scope.row.under_time : "待定"}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="bus_name" label="商家信息" min-width="70">
            <template slot-scope="scope">
              <span class="pointer" @click="$router.push({path:'/merchant/businessAdd',query:{id:scope.row.bus_id}})">{{scope.row.bus_name}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="name" label="状态" min-width="35">
            <template slot-scope="scope">
              <span v-if="tableFormatData.announcement.files.goodsType==='sale'">售卖中</span>
              <span v-if="tableFormatData.announcement.files.goodsType==='hasSale'">已售罄</span>
              <span v-if="tableFormatData.announcement.files.goodsType==='depot'">仓库中</span>
            </template>
          </el-table-column>
          <el-table-column  prop="address" label="操作" min-width="140">
            <template slot-scope="scope">
              <div class="operation-group">
                <router-link
                  class="wlm-text"
                  tag="a"
                  target="_blank"
                  v-if="scope.row.transport_type == 40 && patSetting.plugin.cgp.open"
                :to="{path:'/application/commissionSetting', query:{goods_id:scope.row.goods_id,
                store_user_id:$route.query.store_user_id?$route.query.store_user_id:'',
                  h_aid:$route.query.h_aid?$route.query.h_aid:'',}}">
                  <el-button type="text">单独设置团长佣金</el-button>
                </router-link>
                 <!-- <el-button type="text" @click="openbtn(scope.row.goods_id,scope.row.is_calendar_price)" v-if="scope.row.transport_type == 60 && scope.row.is_calendar_price==2 && scope.row.isexpress==0">开启日历价格</el-button> -->
                 <el-button type="text" @click="openbtn(scope.row.goods_id,scope.row.is_calendar_price)" v-if="scope.row.transport_type == 60 && scope.row.is_calendar_price==1 && scope.row.isexpress==0">价格</el-button>
                <div class="btn-line" v-if="scope.row.transport_type == 60 && scope.row.isexpress==0 && scope.row.is_calendar_price==1 "></div>

                 <div class="btn-line" v-if="scope.row.transport_type == 40 && patSetting.plugin.cgp.open"></div>
                <router-link class="wlm-text" tag="a" target="_blank" :to="{path:'/merchandise/merchandiseManagementAdd', query:{
                  id:scope.row.goods_id,buss_id:scope.row.bus_id,
                  store_user_id:$route.query.store_user_id?$route.query.store_user_id:'',
                  h_aid:$route.query.h_aid?$route.query.h_aid:'',}}">
                </router-link>
                <!-- <router-link class="wlm-text" tag="a" target="_blank" :to="{path:'/merchandise/merchandiseManagementAdd', query:{id:scope.row.goods_id,buss_id:scope.row.bus_id}}">
                  <el-button type="text">编辑</el-button>
                </router-link> -->
                <router-link class="wlm-text" tag="a" target="_blank" :to="{path:'/merchandise/merchandiseManagementAdd', query:{id:scope.row.goods_id,buss_id:scope.row.bus_id}}">
                  <el-button type="text">编辑</el-button>
                </router-link>
                  <div class="btn-line" v-if="scope.row.transport_type == 10 || scope.row.transport_type == 20 "></div>
                   <router-link
                        class="wlm-text"
                        v-if="scope.row.is_reservation == 1"
                        tag="a"
                        target="_blank"
                   :to="{path:'/merchandise/subscribe', query:{
                     goods_id:scope.row.goods_id,is_reservation:scope.row.is_reservation,spec_type:scope.row.spec_type,
                     store_user_id:$route.query.store_user_id?$route.query.store_user_id:'',
                  h_aid:$route.query.h_aid?$route.query.h_aid:'',}}">
                  <el-button type="text">预约</el-button>
                </router-link>
                <div class="btn-line"></div>
                <el-button class="wlm-text" type="text" @click="sharelink(scope.row.goods_id)">推广</el-button>
                <div v-if="scope.row.transport_type!=30" class="btn-line"></div>
                <el-button v-if="scope.row.transport_type!=30&&scope.row.transport_type!=40" class="wlm-text" type="text" @click="changeTableItem({goods_id:scope.row.goods_id},tableFormatData.announcement.change.copy)">复制</el-button>
                <div class="btn-line"></div>
                <!-- <el-button v-if="showActivityBtn(scope.row)" class="wlm-text" type="text" @click="showActivityDialog(scope.row)">活动</el-button>
                <div class="btn-line"></div> -->
                <el-button class="wlm-text" type="text" @click="delTableItem(scope.row.goods_id)">删除</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination-content flex-row flex-justify-b flex-align-c">
          <el-row class="pagination-btns">
            <el-checkbox class="check-all" true-label="1" false-label="0" v-model="tableFormatData.announcement.files.checkall" @change="toggleSelection">全部</el-checkbox>
            <el-button class="right-8" v-if="tableFormatData.announcement.files.goodsType == 'depot'" :disabled="isGroup" size="mini" @click="showDialog('goods_up')">批量上架</el-button>
            <el-button class="right-8" v-if="tableFormatData.announcement.files.goodsType !== 'depot'" :disabled="isGroup" size="mini" @click="changeTableItem({isGroup:true},tableFormatData.announcement.change.goods_down)">批量下架</el-button>
            <el-button class="right-8" :disabled="isGroup" size="mini" @click="delTableList">删除</el-button>
            <el-popover placement="top" width="140" v-model="popvisible">
              <div class="flex-col">
                <el-button size="mini" type="primary" @click="openimgDialog('1')">赠送积分</el-button>
              </div>
              <div class="flex-col" style="margin-top:12px;">
                <el-button size="mini" type="primary" @click="openimgDialog('2')">抵扣积分</el-button>
              </div>
              <el-button slot="reference" size="mini">更多</el-button>
            </el-popover>
          </el-row>
          <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.announcement.pagination.page" :page-sizes="tableFormatData.announcement.pagination.pagesizes" :page-size.sync="tableFormatData.announcement.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.announcement.pagination.total : 0">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  addCommon,
  goodsIndex,
  categoryIndex,
  goodsDelete,
  goodsUpper,
  editGoodsName,
  editGoodsPrice,
  editStockNum,
  goodsDown,
  goodsExtensionInfo,
  goodsSort,
  goodsCopy,
  goodsBalanceSet
} from '@/api/merchandise'
import {
  businessIndex
} from '@/api/merchant'
import mixins from '@/mixins/mixins'
import ShareLink from '@/components/ShareLink/index'
import clipboard from '@/utils/clipboard'
import power from '@/mixins/power'
export default {
  mixins: [mixins.getters('Table'), mixins.getters('Form'), power],
  name: 'ManagementPlatform',
  components: {
    ShareLink
  },
  computed: {
    showActivityBtn(){
      return function(item){
        // console.log('-----------------------start ')
        // console.log(item)
        // member_exclusive 1禁用
        return (item.member_exclusive === 1 || item.transport_type == 30 || item.transport_type == 50 || item.goods_min_price == 0) ? false : true
      }
    },
    linkOrderType(transport_type, isexpress, iszt) {
      return (transport_type, isexpress, iszt) => {
        const orderTypeLinks = {
          10: '/orders/ordersVerificationManagement',
          20: `/orders/orders${isexpress === 0 && iszt === 1 ? 'ComeStore' : 'Express'}Management`,
          30: '/orders/ordersCardPasswordManagement'
        }
        return orderTypeLinks[transport_type]
      }
    }
  },
  created() {
    this.$nextTick(() => {
      categoryIndex().then((response) => {
        const {
          data: {
            data: msgData = []
          }
        } = response
        this.categoryData = msgData
      })
      businessIndex({ list_rows: 'all' }).then((response) => {
        const { data: { data: msgData = [] } } = response
        this.shopData = msgData
      })
    
    })
  },
  data() {
    return {
      selectActivityId: '',
      activityDialog: false,
      activityForm: {
        active: []
      },
      // 0:普通营销；1：秒杀；2：拼团；3：砍价；4：抽奖
      activityList: [
        {
          id: 1,
          name: '加入“秒杀”商品库',
          checked: false,
          disabled: false
        },
        {
          id: 2,
          name: '加入“拼团”商品库',
          checked: false,
          disabled: false
        },
        {
          id: 3,
          name: '加入“砍价”商品库',
          checked: false,
          disabled: false
        }
      ],

      shopData: [],
      shareLinkConfig: {
        current: 'weChatQr',
        params: {
          weChat_short_url:'',
          qrUrl: '',
          linkUrl: '',
          weChatQr: '',
          appQr: ''
        }
      },
      popvisible: false,
      dialogVisibleImg: false,
      openimgDialogType: '',
      rebate: { rebate: 1, max_rebate_money: '', give_integral: '', goods_id: [] },
      category_array: [],
      currentIndex: '',
      currentSort: '',
      goodsType: {
        depot: 0,
        hasSale: 0,
        sale: 0
      },
      myProps: {
        value: 'category_id',
        label: 'name',
        children: 'child'
      },
      $index: -1,
      $type: -1,
      dialogTableVisible: false,
      disabledDateOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7
        }
      },
      categoryData: [],
      formFormatData: {
        key: 'userForm',
        api: {
          editForm: {
            api: '',
            params: {

            }
          },
          submitForm: goodsUpper
        },
        formData: {
          ids: [],
          uppertime: '',
          goods_status: 10
        },
        rules: {}
      },
      tableFormatData: {
        current: 'announcement',
        announcement: {
          key: 'announcement',
          api: {
            getList: goodsIndex,
            delList: goodsDelete
          },
          tableData: [],
          files: {
            sh_status:'',
            transport_type: '',
            goodsType: 'sale',
            name: '',
            business_id: '',
            order: '',
            goods_no: '',
            category_id: '',
            ids: [],
            checkall: '0',
            Recycle: '0',
            redirect: 'goods_id',
            is_reservation: '',
            goods_id:!!this.$route.query.goods_id?this.$route.query.goods_id:'',
          },
          change: {
            goods_name: {
              key: 'goods_name',
              api: editGoodsName
            },
            goods_down: {
              key: 'goods_down',
              api: goodsDown
            },
            goods_price: {
              key: 'goods_price',
              api: editGoodsPrice
            },
            stock_num: {
              key: 'stock_num',
              api: editStockNum
            },
            copy: {
              name: '复制',
              key: 'copy',
              api: goodsCopy
            },
            sort: {
              name: '排序',
              key: 'sort',
              api: goodsSort
            }
          },
          otherData: {},
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      }
    }
  },
  methods: {
    openbtn(goods_id,is_calendar_price){
      console.log("ds9999999999999",is_calendar_price)
      if(is_calendar_price==2){
        this.$confirm('确定要开启日历价格?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            this.$router.push({ path:'/merchandise/calendarprice',query:{goods_id:goods_id,is_calendar_price:1}})
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消！'
          });          
        });
      }else{
         this.$router.push({ path:'/merchandise/calendarprice',query:{goods_id:goods_id,is_calendar_price:1}})
      }
         
    },
    // closebtn(goods_id){
    //     this.$confirm('确定要关闭日历价吗?', '提示', {
    //       confirmButtonText: '确定',
    //       cancelButtonText: '取消',
    //       type: 'warning'
    //     }).then(() => {
    //     calendarTicketPrice({is_calendar_price:2,goods_id:goods_id}).then(res=>{
    //       if(res.data.data.code==1){
    //            this.$message({
    //             type: 'success',
    //             message: '操作成功!'
    //           });
    //       }
    //     })
    //     }).catch(() => {
    //       this.$message({
    //         type: 'info',
    //         message: '已取消!'
    //       });          
    //     });
    // },
    closeActivityDialog() {
      this.activityDialog = false
    },
    // 添加到秒杀商品库
    submitActivityDialog() {
      const _this = this
      addCommon({
        sale_type: this.activityForm.active,
        goods_id: [this.selectActivityId]
      }).then(response => {
        const {
          data: {
            code,
            msg
          }
        } = response
        if (code === 1) {
          _this.$message.success(msg)
        } else {
          _this.$message.error(msg)
        }
        _this.closeActivityDialog()
      })
    },

    showActivityDialog(item) {
      // console.log(item)
      // console.log(this.activityList)
      // console.log(this.config)
      this.activityForm.active = []

      // 禁用秒杀和拼团
      if( item.is_meal == 1 ){
        this.activityList[0].disabled = true
        this.activityList[1].disabled = true
      }
      // 禁用砍价
      if (item.spec_type == 20 || item.is_reservation == 1) {
        this.activityList[2].disabled = true
      }

      this.selectActivityId = item.goods_id
      this.activityDialog = true
    },

    handleClipboard(text, event) {
      clipboard(text, event)
    },
    clearRebate() {
      this.rebate = { rebate: 1, max_rebate_money: '', give_integral: '', goods_id: [] }
    },
    openimgDialog(type) {
      if (this.tableFormatData.announcement.files.ids.length === 0) {
        this.$message.error('请选择商品')
      } else {
        this.popvisible = false
        this.openimgDialogType = type
        this.dialogVisibleImg = true
      }
    },
    saveimgDialog() {
      const result = []
      this.tableFormatData.announcement.files.ids.map(item => {
        result.push(item.goods_id)
      })
      this.rebate.goods_id = result
      goodsBalanceSet(this.rebate).then((response) => {
        const {
          data: {
            code
          }
        } = response
        if (code === 1) {
          this.$message.success('保存成功！')
        }
      })
      this.dialogVisibleImg = false
      this.filesSerch()
    },
    sharelink(goods_id) {
      goodsExtensionInfo({ goods_id }).then((response) => {
        const { data: { data: { weChat_qrcode, wxApp_qrcode, weChat_url, wxApp_url, url,weChat_short_url} } } = response
        this.shareLinkConfig.params.qrUrl = wxApp_url
        this.shareLinkConfig.params.linkUrl = weChat_url
        this.shareLinkConfig.params.weChatQr = weChat_qrcode
        this.shareLinkConfig.params.appQr = wxApp_qrcode
        this.shareLinkConfig.params.url = url
        this.shareLinkConfig.params.weChat_short_url = weChat_short_url
        this.shareLinkConfig.current = weChat_qrcode ? 'weChatQr' : weChat_qrcode ? 'appQr' : ''
      })
      this.$refs.sharelink.toggle()
    },
    mouseenter(row, isshow, btntype) {
      this.$set(this.tableFormatData.announcement.tableData[row.$index], `${btntype}`, isshow)
    },
    filesEmptyBefore() {
      this.category_array = []
      this.filesEmpty()
    },
    categoryChange(category_array) {
      const [category_id] = category_array.slice(-1)
      this.tableFormatData.announcement.files.category_id = category_id
    },
    changeTableCallBack({ event, params: { response: { data: { data: { goods_number } } } } }) {
      if (event === 'getList') {
        this.goodsType = goods_number
      }
    },
    saveDialog() {
      const result = [];
          let  yes_submit = true;
      if (this.tableFormatData.announcement.files.ids.length > 0) {
        this.tableFormatData.announcement.files.ids.map(item => {
          result.push(item.goods_id)
        })
      }
      this.formFormatData.formData.ids = result
      //判断商品是否上架（status==3时未上架）
      this.tableFormatData.announcement.tableData.map(item => {
        this.formFormatData.formData.ids.map(item_to => {
          if(item_to == item.goods_id && item.sh_status == 3){
            this.$message.error('选中商品 '+ item.goods_name + ' 未审核通过，不能上架！');
            yes_submit = false;
            return ;
          }
        })
      })
      if(!yes_submit){
        return ;
      }
      this.formFormatSubmit()
      this.dialogTableVisible = false
      this.clearSelection()
      this.filesSerch()
    },
    showDialog(scope, $type) {
      if (scope) {
        if (!['goods_up'].includes(scope)) {
          this.$index = scope.$index
          this.$type = $type
          this.dialogTableVisible = true
        } else {
          this.$type = scope
          this.dialogTableVisible = true
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.merchandise-management {
  /deep/ .el-tag {
    font-size: 14px;
  }
}
</style>
